VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ClsTipoCliente"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public WithEvents orset As ClsRecordset
Attribute orset.VB_VarHelpID = -1

Public Event DataChanged()

' Public members to implement properties
Public codigo As String
Public tipo As String
Public padreCod As String

Private Sub Class_Initialize()
    Set orset = New ClsRecordset
    orset.setCampos dbCampos(tcl)
    orset.setTablas Array(tcl)
End Sub
Private Sub Class_Terminate()
    Set orset = Nothing
End Sub
' Generic Data management methods
Public Sub consulta(Optional condiciones As Variant)
    orset.consulta condiciones
End Sub
Public Sub consultaSoloHijos()
    Dim sql2 As ClsSQL
    Set sql2 = New ClsSQL
    sql2.setCampos Array(tcl_padre_id)
    sql2.setTablas Array(tcl)
    sql2.setCondiciones Array(tcl_padre_id & " is not null")
    sql2.sSelect
    orset.consulta Array(tcl_id & " not in (" & sql2.cadena & ")")
End Sub
Public Sub consultaDatos(codig As String)
    orset.consulta Array(tcl_id & "=" & codig)
    orset.CierraRec
End Sub

Public Sub consultaPorPrecioAsignado(codpre As String)
    orset.consultaGral , Array(tcl, ptc), _
                       Array(tcl_id & "=" & ptc_tcl_id, _
                             ptc_pre_id & "=" & codpre)
End Sub
Public Sub consultaDeCliente(clicod As String)
    'hay que tomar en cuenta que una consulta plana de las tablas:
    'cliente,tipo_cliente,cliente_tipo_cliente
    'daria como resultado todos los tipos del cliente (o sea asociado,asociado 1ra categoria,etc)
    'es por eso que se filtra a solo aquellos tipos de cliente que son finales (que no tiene subgrupos)
    Dim sql2 As ClsSQL
    Set sql2 = New ClsSQL
    sql2.setCampos Array(tcl_padre_id)
    sql2.setTablas Array(tcl)
    sql2.setCondiciones Array(tcl_padre_id & " is not null")
    sql2.sSelect
    orset.consultaGral , Array(tcl, ctc), _
                       Array(tcl_id & "=" & ctc_tcl_id, _
                             ctc_cli_id & "='" & clicod & "'", _
                             tcl_id & " not in (" & sql2.cadena & ")")
End Sub
Public Sub consultaXCliente(clienteCod As String)
    orset.consultaGral , Array(tcl, ctc), _
                       Array(ctc_tcl_id & "=" & tcl_id, _
                             ctc_cli_id & "='" & clienteCod & "'"), _
                       Array(tcl_padre_id & " DESC", tcl_id & " ASC")
End Sub
'revisando si el codigo es necesario
Public Sub agregaSubGrupo(otroTclCodigo As String)
    orset.sUpdateGral Array(tcl_padre_id), _
                      Array(Me.codigo), _
                      Array(tcl), _
                      Array(tcl_id & "=" & otroTclCodigo), False
End Sub
Private Sub Reload_members()
    ' Reloads the member variables (properties) with the field
    ' values of the current record
    With orset
        codigo = .getDato(tcl_id)
        tipo = .getDato(tcl_tipo)
        padreCod = .getDato(tcl_padre_id)
    End With
    RaiseEvent DataChanged
End Sub
Public Sub Nuevo(newtipo As String, newPadreCod As String)
    orset.sInsert Array("", newtipo, newPadreCod)
End Sub
Public Sub Modificar(codig As String, newtipo As String, newPadreCod As String)
    orset.sUpdate Array(codig, newtipo, newPadreCod)
End Sub
Public Sub Borrar(codig As String)
    orset.sDelete Array(tcl_id & "='" & codig & "'")
End Sub
Public Sub llenaTreeView(tv As TreeView, Optional prk As String = "k")
    orset.consulta , Array(tcl_padre_id, tcl_id)
    While orset.CanMoveNext
        If (Me.padreCod <> "") Then
            tv.Nodes.Add prk & Me.padreCod, tvwChild, prk & Me.codigo, Me.tipo
        Else
            tv.Nodes.Add , , prk & Me.codigo, Me.tipo
        End If
        orset.MoveNext
    Wend
End Sub

Private Sub orset_DataChanged()
    Reload_members
End Sub
